package com.dmai.capacity.platform.user.controller;

import com.dmai.capacity.platform.common.dto.PageResult;
import com.dmai.capacity.platform.common.dto.ResponseEntity;
import com.dmai.capacity.platform.user.model.SysConfig;
import com.dmai.capacity.platform.user.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;

/**
 * @author
 * @email
 * @date 2021-08-18 11:05:17
 */
@RestController
@RequestMapping("configs")
public class SysConfigController {

    @Autowired
    private ISysConfigService configService;

    /**
     * 列表
     */
    @GetMapping("/configs")
//    @PreAuthorize("hasAnyAuthority('sys_config:sysconfig:list')")
    public PageResult list(@RequestParam Map<String, Object> params) {
        PageResult pageResult = configService.pageAll(params);
        return pageResult;
    }

    /**
     * 查询单条记录
     */
    @GetMapping("/configs/{key}")
//    @PreAuthorize("hasAnyAuthority('sys_config:sysconfig:list')")
    public ResponseEntity findByKey(@PathVariable(value = "id") String key) {
        return ResponseEntity.succeed(configService.findByKey(key));
    }

    /**
     * 保存
     */
    @PutMapping("/configs")
//    @PreAuthorize("hasAnyAuthority('sys_config:sysconfig:save')")
    public ResponseEntity update(@RequestBody @Valid SysConfig sysConfig) {
        configService.update(sysConfig);
        return ResponseEntity.succeed("操作成功");
    }
}
